package org.goj.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.goj.common.entity.user.Topic;
import org.goj.user.mapper.TopicMapper;
import org.goj.user.service.TopicService;
import org.goj.user.vo.SevenRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 论坛帖子表 服务实现类
 * </p>
 *
 * @author CK
 * @since 2020-12-02
 */
@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements TopicService {

    @Resource
    private TopicMapper topicMapper;

    @Override
    public Page<Topic> listTopic() {
        QueryWrapper<Topic> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0).orderByDesc("in_date");
        Page<Topic> page = new Page<>(1, 5);
        return super.page(page, queryWrapper);
    }

    @Override
    public List<SevenRecordVO> sevenRecord() {
        return topicMapper.sevenRecord();
    }

    @Override
    public List<Topic> adminListTopic(Integer topicId) {
        QueryWrapper<Topic> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("status").orderByDesc("in_date")
                .eq(topicId != -1, "topic_id", topicId);
        return super.list(queryWrapper);
    }
}
